{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4c7effb3",
   "metadata": {},
   "source": [
    "## Day 1 Challenge : Building simple commercial agent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9a03f44b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from IPython.display import display, Markdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fe76fcc1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_dotenv(override=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4c4eff9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "openai_client = OpenAI()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0052fa9",
   "metadata": {},
   "source": [
    "### Creting Scope for ai agent in business"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "82966ccd",
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [{\"role\": \"user\", \"content\": \"Pick a business area that might be worth exploring for an agentic AI opportunity\"}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8e0fd075",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "One promising business area for exploring an agentic AI opportunity is **personalized healthcare management**.\n",
      "\n",
      "### Why personalized healthcare management?\n",
      "\n",
      "- **Complex, dynamic decisions:** Agents can help navigate complex medical data, patient history, and real-time health metrics to provide tailored health recommendations.\n",
      "- **Continuous learning and adaptation:** Healthcare needs can change rapidly, and agentic AI systems can learn and adapt treatment plans and wellness suggestions accordingly.\n",
      "- **Autonomous actions:** AI agents could proactively schedule appointments, manage medication reminders, or alert caregivers and doctors about critical changes.\n",
      "- **Data integration:** Agentic AI can integrate data from wearables, electronic health records, genetic information, and lifestyle inputs to optimize individual health outcomes.\n",
      "- **Scalability:** Personalized healthcare is relevant to a broad population, enabling scalable deployment across various demographics and conditions.\n",
      "\n",
      "### Potential applications\n",
      "\n",
      "- AI health coaches that autonomously adjust diet, exercise, mental health routines based on real-time feedback.\n",
      "- Chronic disease management agents that dynamically adapt medication plans and alert providers when intervention is needed.\n",
      "- Post-operative recovery assistants managing medication, physical therapy exercises, and symptoms monitoring.\n",
      "- Preventive care advisors identifying early signs of potential health issues and recommending screening tests or lifestyle changes.\n",
      "\n",
      "Exploring agentic AI in personalized healthcare management could significantly improve patient outcomes, reduce healthcare costs, and empower individuals to take more proactive control of their health.\n"
     ]
    }
   ],
   "source": [
    "response = openai_client.chat.completions.create(\n",
    "    model=\"gpt-4.1-mini\",\n",
    "    messages=messages,\n",
    "    max_tokens=1000,\n",
    ")\n",
    "\n",
    "scope_for_business_for_ai_agent = response.choices[0].message.content.strip()\n",
    "\n",
    "print(scope_for_business_for_ai_agent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "30f79682",
   "metadata": {},
   "outputs": [],
   "source": [
    "# form a question to ask the AI agent based on the scope\n",
    "\n",
    "messages = [{\"role\": \"user\", \"content\": scope_for_business_for_ai_agent + \" Present a pain point in this industry -  something challenging that might be ripe for an agentic solution?\"}]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "133ac292",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A significant pain point in personalized healthcare management is **the fragmentation and complexity of patient data**, which leads to inadequate coordination and delayed or suboptimal care decisions.\n",
      "\n",
      "### Why this is a critical pain point:\n",
      "\n",
      "- **Disparate data sources:** Patient data is scattered across multiple platforms — electronic health records (EHRs) from different providers, lab results, wearable devices, pharmacy records, and patient self-reports. This fragmentation makes it difficult for healthcare professionals to have a holistic, up-to-date view of the patient’s health.\n",
      "- **Data overload and complexity:** Physicians and care teams are often overwhelmed by the volume and complexity of health data, making it challenging to identify critical changes or trends promptly.\n",
      "- **Manual coordination inefficiencies:** Coordinating care among specialists, primary care providers, therapists, and caregivers often relies on manual communication methods (phone calls, emails, patient visits), leading to delays, miscommunications, and care gaps.\n",
      "- **Delayed response to health changes:** Without continuous, integrated data monitoring and proactive alerting, critical health deteriorations (e.g., early signs of infection, medication non-adherence) can go unnoticed until they become emergencies.\n",
      "- **Patient burden:** Patients frequently have to manage fragmented information themselves, track appointments, follow complex medication schedules, and communicate symptoms across multiple providers, which is error-prone and stressful.\n",
      "\n",
      "### How an agentic AI could address this pain point:\n",
      "\n",
      "- **Unified data integration:** An intelligent agent could autonomously aggregate and harmonize data from diverse sources, maintaining a real-time, comprehensive, and personalized health profile.\n",
      "- **Smart prioritization and alerts:** The AI can continuously analyze integrated data to detect significant deviations or risk patterns, prioritizing alerts for patients and providers to focus attention where it’s most needed.\n",
      "- **Automated coordination:** The agent can autonomously schedule appointments, recommend necessary tests, coordinate medication refills, and communicate updates among all stakeholders, reducing manual workload and errors.\n",
      "- **Patient engagement and support:** Acting as a personal health assistant, the AI can proactively remind patients about medications, prepare them for upcoming visits, interpret complex information in simple terms, and coach behavioral changes.\n",
      "- **Adaptive learning:** The system can learn individual patient patterns over time, refining recommendations and predictions to optimize health outcomes dynamically.\n",
      "\n",
      "**In summary**, by tackling the fragmented, overwhelming nature of patient data and care coordination, an agentic AI solution could fundamentally improve the efficiency, effectiveness, and patient-centeredness of personalized healthcare management.\n"
     ]
    }
   ],
   "source": [
    "response = openai_client.chat.completions.create(\n",
    "    model=\"gpt-4.1-mini\",\n",
    "    messages=messages,\n",
    "    max_tokens=1000,\n",
    ")\n",
    "\n",
    "pain_point = response.choices[0].message.content.strip()\n",
    "\n",
    "print(pain_point)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f079e2f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# form a solution - 3rd call\n",
    "messages = [{\"role\": \"user\", \"content\": pain_point + \" Propose an agentic AI practical solution to it.\"}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38e413d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "Certainly! Here’s a practical, agentic AI solution proposal designed to address the fragmentation and complexity of patient data in personalized healthcare management.\n",
       "\n",
       "---\n",
       "\n",
       "### **Agentic AI Solution: Holistic Health Agent (HHA)**\n",
       "\n",
       "**Overview:**  \n",
       "The Holistic Health Agent (HHA) is an autonomous AI assistant that acts as the central coordinator and integrator of all patient health data and care workflows. It leverages advanced data integration, natural language understanding, predictive analytics, and autonomous communication capabilities to streamline healthcare delivery for patients, providers, and caregivers.\n",
       "\n",
       "---\n",
       "\n",
       "### **Core Components and Functionality**\n",
       "\n",
       "#### 1. **Unified Data Integration Layer**\n",
       "- **Automated Data Aggregation:** HHA connects via secure APIs with EHR systems, lab databases, wearable device platforms (e.g., Fitbit, Apple Health), pharmacy systems, and patient apps.\n",
       "- **Data Harmonization & Normalization:** Uses AI to standardize formats, resolve conflicts (e.g., different lab units), and maintain a continually updated, comprehensive longitudinal patient record.\n",
       "- **Privacy-by-Design:** Implements HIPAA-compliant encryption, consent management, and role-based data access controls.\n",
       "\n",
       "#### 2. **Intelligent Data Prioritization & Alerting**\n",
       "- **Continuous Monitoring:** Employs real-time data streams (wearables, labs, reported symptoms) to detect anomalies, trends, or risk signals.\n",
       "- **Risk Stratification:** Applies predictive models (e.g., for deterioration, medication non-adherence, readmission risk) personalized per patient.\n",
       "- **Smart Alerts & Insight Summaries:** Prioritizes and delivers actionable alerts to providers and patients via preferred channels (mobile app notifications, secure messaging) with recommended next steps.\n",
       "\n",
       "#### 3. **Autonomous Care Coordination**\n",
       "- **Scheduling Assistant:** Automatically proposes and books appointments, labs, or imaging with specialists and primary care based on medical guidelines and patient availability.\n",
       "- **Medication Management:** Monitors prescriptions, detects scheduling conflicts or refill needs, and coordinates pharmacy interactions.\n",
       "- **Inter-provider Communication:** Generates and transmits standardized clinical summaries, updates, and referrals, reducing reliance on manual calls or faxes.\n",
       "- **Care Team Dashboard:** Provides a shared, real-time view of patient status and care plans accessible to all authorized providers and caregivers.\n",
       "\n",
       "#### 4. **Patient-Centered Engagement & Support**\n",
       "- **Personal Health Coach:** Sends reminders for medications, appointments, and lifestyle activities; explains complex medical information using natural language generation.\n",
       "- **Symptom Logging & Triage:** Guides patients through symptom checkers; escalates serious alerts to providers autonomously.\n",
       "- **Behavioral Nudges:** Uses tailored motivational coaching for diet, exercise, medication adherence based on learned patient preferences.\n",
       "- **Accessible Interfaces:** Supports voice commands, chatbots, and mobile apps for diverse patient populations.\n",
       "\n",
       "#### 5. **Adaptive Learning & Continuous Improvement**\n",
       "- **Personalized Models:** Utilizes reinforcement learning to adapt alert thresholds, coaching tone, and care coordination logic to individual patient responses.\n",
       "- **Outcome Feedback Loop:** Ingests outcomes data and provider feedback to refine risk models and workflows, improving accuracy and relevance over time.\n",
       "\n",
       "---\n",
       "\n",
       "### **Use-Case Workflow Example**\n",
       "\n",
       "1. **Data Aggregation:** Patient’s wearable reports elevated heart rate and disrupted sleep; a recent lab shows rising inflammatory markers.\n",
       "2. **Risk Detection:** HHA’s AI flags potential early infection signs and prioritizes alerting patient and provider.\n",
       "3. **Care Coordination:** The agent autonomously schedules an urgent lab retest and a specialist teleconsultation.\n",
       "4. **Patient Support:** It sends the patient an easy-to-understand explanation of the potential issue, medication reminders, and preparation tips for the upcoming visit.\n",
       "5. **Outcome Tracking:** Post-visit data and patient feedback inform the AI’s predictive model adjustments.\n",
       "\n",
       "---\n",
       "\n",
       "### **Technical & Implementation Considerations**\n",
       "\n",
       "- **Interoperability Standards:** Leverage HL7 FHIR, SMART on FHIR, and other industry standards for seamless integration.\n",
       "- **Explainability & Trust:** Incorporate transparent AI decision explanations to build provider and patient confidence.\n",
       "- **Human-in-the-Loop:** Enable providers to override or refine AI recommendations, ensuring clinical judgment remains paramount.\n",
       "- **Scalability & Deployment:** Cloud-native architecture with strong security and low latency for real-time responsiveness.\n",
       "\n",
       "---\n",
       "\n",
       "### **Impact**\n",
       "\n",
       "- **Reduced clinician cognitive overload and burnout** by delivering precise, prioritized insights.\n",
       "- **Improved patient adherence and engagement** through proactive coaching and simplified communication.\n",
       "- **Enhanced care coordination efficiency** by automating fragmented manual processes.\n",
       "- **Earlier detection of clinical deterioration** leading to timely interventions and better outcomes.\n",
       "- **Empowered patients** with agency over their healthcare journey and clearer understanding.\n",
       "\n",
       "---\n",
       "\n",
       "**In summary**, the Holistic Health Agent offers a comprehensive, autonomous solution that dissolves data silos, streamlines coordination, and fosters proactive, personalized care — fundamentally transforming personalized healthcare management for patients and providers alike."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = openai_client.chat.completions.create(\n",
    "    model=\"gpt-4.1-mini\",\n",
    "    messages=messages,\n",
    "    max_tokens=1000,\n",
    ")\n",
    "\n",
    "solution = response.choices[0].message.content.strip()\n",
    "display(Markdown(solution))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c7fbfd3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
